package com.tiyo.wechat.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.tiyo.common.core.domain.AjaxResult;
import com.tiyo.wechat.service.WechatService;

@RequestMapping("/wechat")
@Controller
public class WeChatController {
	@Autowired
	WechatService wechatService;
	@GetMapping("/token")
	@ResponseBody
	public AjaxResult token(String appid,String secret) {
		return AjaxResult.success("操作成功",wechatService.getToken(appid, secret));
	}
	@GetMapping("/oauth2")
	@ResponseBody
	public AjaxResult oauth2(String appid,String secret,String code) {
		return AjaxResult.success("操作成功",wechatService.auth2(appid, secret, code));
	}
	@PostMapping("/message/template/send")
	@ResponseBody
	public AjaxResult send(String token,@RequestBody JSONObject message) {
		return AjaxResult.success("操作成功",wechatService.sendMsg(token, message));
	}
}
